1
'***************************** Module Header ******************************\
2 '* Module Name: Default.aspx.vb
3 '* Project: VBASPNETFileUploadStatus
4 '* Copyright (c) Microsoft Corporation
6 '* The project illustrates how to display the upload status and progress without
7 '* a third part component like ActiveX control, Flash or Silverlight.
9 '* This is the page which we test the Upload status for the client
10 '* We use ICallbackEventHandler to realize the communication between
11 '* the server side and client side without refresh the page.
12 '* But we need to use an iframe to hold the upload controls and buttons,
13 '* because the upload need postback to the server, we can't call the server code
14 '* by javascript in one postback page.
15 '* So we let the iframe do the upload postback operation.
17 '* For more details about ICallbackEventHandler,
18 '* please read the readme file in the root directory.
20 '* This source is subject to the Microsoft Public License.
21 '* See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
22 '* All other rights reserved.
23 '\****************************************************************************
27 Imports System
.Collections
.Generic
31 Imports System
.Web
.UI
.WebControls
32 Imports System
.Threading
33 Imports System
.Web
.Script
.Serialization
35 Imports VBASPNETFileUploadStatus
38 Partial
Public Class _Default
39 Inherits System
.Web
.UI
.Page
40 Implements ICallbackEventHandler
42 Protected
Sub Page_Load(ByVal sender
As Object, ByVal e
As EventArgs
)
43 'Register a client script for ICallbackEventHandler
44 Dim cm
As ClientScriptManager
= Page
.ClientScript
45 Dim cbReference
As String = cm
.GetCallbackEventReference(Me, "arg", "ReceiveServerData", "")
46 Dim callbackScript
As String = "function CallServer(arg, context) {" & cbReference
& "; }"
47 cm
.RegisterClientScriptBlock(Me.[GetType
](), "CallServer", callbackScript
, True)
51 Private uploadModuleProgress
As String = ""
52 Public Function GetCallbackResult() As String Implements ICallbackEventHandler
.GetCallbackResult
53 Return uploadModuleProgress
56 Public Sub RaiseCallbackEvent(ByVal eventArgument
As String) Implements ICallbackEventHandler
.RaiseCallbackEvent
57 If eventArgument
= "Clear" Then
58 'operation for clear the cache
60 uploadModuleProgress
= "Cleared"
62 If eventArgument
= "Abort" Then
63 'operation for abort uploading
65 uploadModuleProgress
= "Aborted"
69 Dim state
As UploadStatus
= TryCast(HttpContext
.Current
.Cache("fuFile"), UploadStatus
)
70 If state Is
Nothing Then
73 ' We use JSON to send the data to the client,
74 ' because it is simple and easy to handle.
75 ' For more details about JavaScriptSerializer, please
76 ' read the readme file in the root directory.
77 Dim jss
As New JavaScriptSerializer()
79 ' The StringBuilder object will hold the serialized result.
80 Dim sbUploadProgressResult
As New StringBuilder()
81 jss
.Serialize(state
, sbUploadProgressResult
)
83 uploadModuleProgress
= sbUploadProgressResult
.ToString()
84 Catch err
As Exception
85 If err
.InnerException IsNot
Nothing Then
86 uploadModuleProgress
= "Error:" + err
.InnerException
.Message
88 uploadModuleProgress
= "Error:" + err
.Message
93 Private Sub AbortUpload(ByVal cacheID
As String)
94 Dim state
As UploadStatus
= TryCast(HttpContext
.Current
.Cache(cacheID
), UploadStatus
)
95 If state Is
Nothing Then
102 Private Sub ClearCache(ByVal cacheID
As String)
103 HttpContext
.Current
.Cache
.Remove(cacheID
)